﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Physio10Context;
using DatabaseManager;

namespace Physio_Clinic
{
    public partial class WebForm6 : System.Web.UI.Page
    {
        public Qf8soUser currentUser;

        protected void Page_Load(object sender, EventArgs e)
        {
            currentUser = null;
            if (Session["currentUser"] != null)
            {
                currentUser = (Qf8soUser)Session["currentUser"];
            }

            if (Session["currentOpenDate"] != null)
            {
                Opendate opendate = (Opendate)Session["currentOpenDate"];


                if (!Page.IsPostBack)
                {
                    Label9.Text = opendate.DayOfweekName;
                    DropDownDateStatus.SelectedValue = opendate.OpenStatus.ToString();
                    DoctorDropDownList.SelectedValue = opendate.DoctorId.ToString();
                }
            }
        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            string value = (string)e.CommandArgument;

            Opendate select_row = PersistentManager.Instance.GetOpenDate(Convert.ToInt32(value));
            //current_drug = PersistentManager.Instance.GetDrug(Convert.ToInt32(value1));

            Session["currentOpenDate"] = select_row;

            Response.Redirect("./OpenDate.aspx");

        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                Button myButton = (Button)e.Row.Cells[0].Controls[0];

                if (e.Row.DataItem != null)
                {
                    myButton.CommandArgument = ((Opendate)e.Row.DataItem).Id.ToString();
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
             Opendate opendate = (Opendate)Session["currentOpenDate"];

             if(opendate != null)
             {
                 opendate.OpenStatus = Convert.ToInt32(DropDownDateStatus.SelectedValue);
                 opendate.DoctorId = Convert.ToInt32(DoctorDropDownList.SelectedValue);

                 PersistentManager.Instance.Save();

                 Response.Redirect("./OpenDate.aspx");
             }
        }
    }
}